package com.mc.demo.pages

import android.os.Bundle
import com.google.android.material.shape.CutCornerTreatment
import com.google.android.material.shape.RoundedCornerTreatment
import com.mc.demo.R
import com.mc.demo.databinding.ActivityShadowViewBinding
import com.mc.fastkit.ext.singleClick
import com.mc.fastkit.ext.toast
import com.mc.fastkit.view.StateType

class ShadowViewActivity : BaseFrameActivity<ActivityShadowViewBinding>() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.rgEnableShadow.setOnCheckedChangeListener { _, checkedId ->
            binding.shadowView.setShadowEnable(checkedId == R.id.rg_enable_shadow_yes).setup()
        }
        binding.rgAutoInset.setOnCheckedChangeListener { _, checkedId ->
            binding.shadowView.setAutoInset(checkedId == R.id.rg_autoInset_yes).setup()
        }
        binding.rgFollow.setOnCheckedChangeListener { _, checkedId ->
            binding.shadowView.setShadowFollowContent(checkedId == R.id.rg_follow_yes).setup()
        }
        binding.rgStateType.setOnCheckedChangeListener { group, checkedId ->
            binding.shadowView.setStateType(
                StateType.from(group.indexOfChild(findViewById(checkedId)))
            ).setup()
        }
        binding.rgSwitchState.setOnCheckedChangeListener { _, checkedId ->
            when (checkedId) {
                binding.rbNone.id -> {
                    binding.shadowView.isEnabled = true
                    binding.shadowView.isSelected = false
                }

                binding.rbSelected.id -> {
                    binding.shadowView.isEnabled = true
                    binding.shadowView.isSelected = true
                }

                binding.rbChecked.id -> {}
                binding.rbDisable.id -> {
                    binding.shadowView.isEnabled = false
                    binding.shadowView.isSelected = false
                }
            }
        }
        binding.sbStrokeWidth.addOnChangeListener { _, value, _ ->
            binding.shadowView.setStrokeWidth(value).setup()
        }
        binding.sbElevation.addOnChangeListener { _, value, _ ->
            binding.shadowView.setShadowElevation(value).setup()
        }
        binding.sbElevationOffsetx.addOnChangeListener { _, value, _ ->
            binding.shadowView.setShadowOffsetX(value).setup()
        }
        binding.sbElevationOffsety.addOnChangeListener { _, value, _ ->
            binding.shadowView.setShadowOffsetY(value).setup()
        }
        //TopLeftCorner
        binding.topLeftCornerLayout.cornerModelData.observe(this) {
            binding.shadowView.setTopLeftCorner(
                if (it == 0) RoundedCornerTreatment() else CutCornerTreatment()
            ).setup()
        }
        binding.topLeftCornerLayout.cornerSizeData.observe(this) {
            binding.shadowView.setTopLeftCornerSize(it).setup()
        }
        //TopRightCorner
        binding.topRightCornerLayout.cornerModelData.observe(this) {
            binding.shadowView.setTopRightCorner(
                if (it == 0) RoundedCornerTreatment() else CutCornerTreatment()
            ).setup()
        }
        binding.topRightCornerLayout.cornerSizeData.observe(this) {
            binding.shadowView.setTopRightCornerSize(it).setup()
        }
        //BottomLeftCorner
        binding.bottomLeftCornerLayout.cornerModelData.observe(this) {
            binding.shadowView.setBottomLeftCorner(
                if (it == 0) RoundedCornerTreatment() else CutCornerTreatment()
            ).setup()
        }
        binding.bottomLeftCornerLayout.cornerSizeData.observe(this) {
            binding.shadowView.setBottomLeftCornerSize(it).setup()
        }
        //BottomRightCorner
        binding.bottomRightCornerLayout.cornerModelData.observe(this) {
            binding.shadowView.setBottomRightCorner(
                if (it == 0) RoundedCornerTreatment() else CutCornerTreatment()
            ).setup()
        }
        binding.bottomRightCornerLayout.cornerSizeData.observe(this) {
            binding.shadowView.setBottomRightCornerSize(it).setup()
        }
    }
}